package com.xuecheng.commons.utils;

import com.xuecheng.commons.model.vo.AuthInfo;

/**
 * 存放authInfo的本地线程
 *
 * @author 七安
 */
public class AuthInfoThreadLocal {

    private static final ThreadLocal<AuthInfo> threadLocal = new ThreadLocal<>();

    /**
     * 存入authInfo
     */
    public static void setAuthInfo(AuthInfo authInfo) {
        threadLocal.set(authInfo);
    }

    /**
     * 获取authInfo
     */
    public static AuthInfo getAuthInfo() {
        return threadLocal.get();
    }

    /**
     * 获取authInfo中的userId
     */
    public static Long getUserId() {
        if (threadLocal.get() != null) {
            return threadLocal.get().getUid();
        }
        return null;
    }

    /**
     * 获取authInfo中的companyId
     */
    public static Long getCompanyId() {
        if (threadLocal.get() != null) {
            return threadLocal.get().getCompanyId();
        }
        return null;
    }

    /**
     * 删除本地线程的内容
     */
    public static void remove() {
        threadLocal.remove();
    }
}
